package com.team.mpc.config.sentinel;

import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;

//sentinel授权规则，制定请求中的授权标识位置
//@Component
public class RequestOriginParserDefinition implements RequestOriginParser {
    @Override
    public String parseOrigin(HttpServletRequest httpServletRequest) {
        String authRule = httpServletRequest.getParameter("authRule");
        if (StringUtils.isEmpty(authRule)){
            throw new RuntimeException("授权规则authRule字段不能为空");
        }
        return authRule;
    }
}
